//
//  DetailHouseDataManage.m
//  WGFGlobalHouses
//
//  Created by waiguofang on 15/5/6.
//  Copyright (c) 2015年 waiguofang. All rights reserved.
//

#import "HouseListDataManage.h"
#import "HouseTypeCellModel.h"
#import "HouseTypeData.h"
#import "API.h"
#import "JSONKit.h"


@interface HouseListDataManage()
@property(nonatomic,assign)NSInteger pageIndex;

@end

@implementation HouseListDataManage

//参数：consumerId：登录者ID，currpage:当前页，perItem：每页个数，premisesId：楼盘ID，isForwardDelivery：房屋类型，现房：0，期房：1，样板房：2
-(ResulteMod *)refreshDataWithPremisesId:(NSString *)premisesId WithIsForwardDelivery:(NSString *)isForwardDelivery WithConsumerId:(NSString *)consumerId ;
{
    self.pageIndex = 1;
    NSString *url = [NSString stringWithFormat:@"%@%@/%@/%@/%ld/10",[API urlMake:fangxingList],premisesId,isForwardDelivery,consumerId,(long)self.pageIndex];
    
    ResulteMod *mod = [Connect doGetWithCaChe:url];
    
    NSDictionary *resDic = [mod.resultData objectFromJSONStringWithParseOptions:JKParseOptionLooseUnicode];
    
    NSDictionary *abstractResponseDic = resDic[@"abstractResponse"];
     NSLog(@"数据－－－ %@",abstractResponseDic);
    //全部的房源数
    NSString *housingCount = abstractResponseDic[@"housingCount"];
    NSString *premisesComment = abstractResponseDic[@"premisesComment"];
    NSString *premisesName = abstractResponseDic[@"premisesName"];
    mod.otherDataMod = [[NSArray alloc]initWithObjects:housingCount,premisesComment,premisesName,nil];
    
    NSArray *mainArray = abstractResponseDic[@"housingListDtos"];
    
    NSMutableArray *arr = [[NSMutableArray alloc]init];
    
    for (NSDictionary *dic in mainArray)
    {
        HouseTypeCellModel *data = [[HouseTypeCellModel alloc]initWithDic:dic];
        [arr addObject:data];
    }
    if (arr.count > 0)
    {
        self.pageIndex ++;
    }
    mod.dataMod = arr;
    
    return mod;
    
}
-(NSArray *)loadMoreDataWithPremisesId:(NSString *)premisesId WithIsForwardDelivery:(NSString *)isForwardDelivery WithConsumerId:(NSString *)consumerId

{
       NSString *url = [NSString stringWithFormat:@"%@%@/%@/%@/%ld/10",[API urlMake:fangxingList],premisesId,isForwardDelivery,consumerId,(long)self.pageIndex];
    
    ResulteMod *mod = [Connect doGetWithCaChe:url];
    
    NSDictionary *resDic = [mod.resultData objectFromJSONStringWithParseOptions:JKParseOptionLooseUnicode];
    
    NSDictionary *abstractResponseDic = resDic[@"abstractResponse"];
    NSLog(@"数据－－－ %@",abstractResponseDic);
    //全部的房源数
    NSString *housingCount = abstractResponseDic[@"housingCount"];
    NSString *premisesComment = abstractResponseDic[@"premisesComment"];
    NSString *premisesName = abstractResponseDic[@"premisesName"];
    mod.otherDataMod = [[NSArray alloc]initWithObjects:housingCount,premisesComment,premisesName,nil];
    
    NSArray *mainArray = abstractResponseDic[@"housingListDtos"];
    
    NSMutableArray *arr = [[NSMutableArray alloc]init];
    
    for (NSDictionary *dic in mainArray)
    {
        HouseTypeCellModel *model = [[HouseTypeCellModel alloc]initWithDic:dic];
        [arr addObject:model];
    }
    if (arr.count > 0)
    {
        self.pageIndex ++;
    }
    return arr;

}
@end
